﻿<UserControl x:Class="CustomerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:t="clr-namespace:NavigationExample"
             xmlns:n="http://wpfglue.wordpress.com/navigation"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="5"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)/ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <UserControl.BindingGroup>
        <BindingGroup/>
    </UserControl.BindingGroup>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Label x:Name="NameLabel" Target="{Binding ElementName=NameTextBox}">_Name</Label>
        <Label x:Name="AddressLabel" Grid.Row="1" Target="{Binding ElementName=AddressTextBox}">_Address</Label>
        <Label x:Name="CityLabel" Grid.Row="2" Target="{Binding ElementName=CityTextBox}">_City</Label>
        <Label x:Name="CountryLabel" Grid.Row="3" Target="{Binding ElementName=CountryTextBox}">C_ountry</Label>
        <TextBox x:Name="NameTextBox" Grid.Column="1">
            <TextBox.Text>
                <Binding Path="Name" UpdateSourceTrigger="LostFocus">
                    <Binding.ValidationRules>
                        <t:MustHaveValueValidationRule ValidatesOnTargetUpdated="True"/>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
        <TextBox x:Name="AddressTextBox" Grid.Column="1" Grid.Row="1" Text="{Binding Path=Address, UpdateSourceTrigger=LostFocus}"/>
        <TextBox x:Name="CityTextBox" Grid.Column="1" Grid.Row="2" Text="{Binding Path=City, UpdateSourceTrigger=LostFocus}"/>
        <TextBox x:Name="CountryTextBox" Grid.Column="1" Grid.Row="3" Text="{Binding Path=Country, UpdateSourceTrigger=LostFocus}"/>
        <StackPanel Grid.Column="1" Grid.Row="4" Orientation="Horizontal">
            <Button x:Name="SelectNewButton" Command="GoToPage" n:Navigation.Uri="ListPage.xaml" VerticalAlignment="Top">Select Other Customer</Button>
            <Button x:Name="GCButton" Click="GCButton_Click" VerticalAlignment="Top">GC</Button>
        </StackPanel>
    </Grid>
</UserControl>
